# _*_ coding utf-8 _*_
# george
# time: 2025/1/15上午8:37
# name: file.py
# comment:
from flask import Blueprint, redirect, render_template, request, abort, send_from_directory, session, url_for
import logging
from model.file import File

file_logger = logging.getLogger("file的controller:")

file = Blueprint("file", __name__)


@file.route("/detail")
def file_detail():
    file_name = request.args.get("file_name")
    pdf_file = File().get_file_detail(file_name)
    return render_template('file_info.html', filename=file_name, file=pdf_file)


@file.route('/get_pdf/<filename>')
def get_pdf(filename):
    try:
        pdf_file = File().get_file(filename)
        return pdf_file
    except FileNotFoundError:
        abort(404)


@file.route("/showfile_project")
def show_file_group():
    # 获取当前页面的页数
    page = request.args.get("page")
    file_logger.debug(f"page:{page}")
    if page is None:
        page = 1
        # 文件查询功能
    project_id = request.args.get("project_id")
    # group_files = File().showfile_group(project_id, page)
    session["project_id"] = project_id
    target_url = url_for('index.get_home')
    return redirect(target_url)

    # return render_template("home.html", db_result=group_files, user_info=session["user_info"])


@file.route("/showfile_team")
def show_file_team():
    # 获取当前页面的页数
    page = request.args.get("page")
    file_logger.debug(f"page:{page}")
    if page is None:
        page = 1
        # 文件查询功能
    team_id = request.args.get("team_id")
    session["team_id"] = team_id
    # group_files = File().showfile_team(team_id, page)
    target_url = url_for('index.get_home')
    return redirect(target_url)
